package fairygui.editor.gui
{
   import fairygui.editor.utils.UtilsStr;
   
   public class ETransitionValue
   {
       
      
      public var a:Number;
      
      public var b:Number;
      
      public var alpha:Number;
      
      public var rotation:Number;
      
      public var color:uint;
      
      public var playing:Boolean;
      
      public var frame:int;
      
      public var sound:String;
      
      public var volume:int;
      
      public var transName:String;
      
      public var transTimes:int;
      
      public var shakeAmplitude:int;
      
      public var shakePeriod:Number;
      
      public var visible:Boolean;
      
      public var c:Number;
      
      public var d:Number;
      
      public var aEnabled:Boolean;
      
      public var bEnabled:Boolean;
      
      public var filter_cb:Number = 0;
      
      public var filter_cc:Number = 0;
      
      public var filter_cs:Number = 0;
      
      public var filter_ch:Number = 0;
      
      public function ETransitionValue()
      {
         super();
         this.aEnabled = true;
         this.bEnabled = true;
         this.transTimes = 1;
      }
      
      public function assign(param1:ETransitionValue) : void
      {
         this.a = param1.a;
         this.b = param1.b;
         this.alpha = param1.alpha;
         this.rotation = param1.rotation;
         this.color = param1.color;
         this.playing = param1.playing;
         this.frame = param1.frame;
         this.aEnabled = param1.aEnabled;
         this.bEnabled = param1.bEnabled;
         this.sound = param1.sound;
         this.volume = param1.volume;
         this.transName = param1.transName;
         this.transTimes = param1.transTimes;
         this.shakeAmplitude = param1.shakeAmplitude;
         this.shakePeriod = param1.shakePeriod;
         this.c = param1.c;
         this.d = param1.d;
         this.visible = param1.visible;
         this.filter_cb = param1.filter_cb;
         this.filter_cc = param1.filter_cc;
         this.filter_cs = param1.filter_cs;
         this.filter_ch = param1.filter_ch;
      }
      
      public function decode(param1:String, param2:String) : void
      {
         var _loc3_:Array = null;
         switch(param1)
         {
            case "XY":
            case "Size":
            case "Pivot":
               _loc3_ = param2.split(",");
               if(_loc3_[0] == "-")
               {
                  this.aEnabled = false;
               }
               else
               {
                  this.a = parseFloat(_loc3_[0]);
                  this.aEnabled = true;
               }
               if(_loc3_.length == 1 || _loc3_[1] == "-")
               {
                  this.bEnabled = false;
               }
               else
               {
                  this.b = parseFloat(_loc3_[1]);
                  this.bEnabled = true;
               }
               if(isNaN(this.a))
               {
                  this.a = 0;
               }
               if(isNaN(this.b))
               {
                  this.b = 0;
               }
               break;
            case "Alpha":
               this.alpha = parseFloat(param2);
               if(isNaN(this.alpha))
               {
                  this.alpha = 1;
               }
               break;
            case "Rotation":
               this.rotation = parseInt(param2);
               break;
            case "Scale":
               _loc3_ = param2.split(",");
               this.a = parseFloat(_loc3_[0]);
               this.b = parseFloat(_loc3_[1]);
               if(isNaN(this.a))
               {
                  this.a = 1;
               }
               if(isNaN(this.b))
               {
                  this.b = 1;
               }
               break;
            case "Skew":
               _loc3_ = param2.split(",");
               this.a = parseFloat(_loc3_[0]);
               this.b = parseFloat(_loc3_[1]);
               if(isNaN(this.a))
               {
                  this.a = 0;
               }
               if(isNaN(this.b))
               {
                  this.b = 0;
               }
               break;
            case "Color":
               this.color = UtilsStr.convertFromHtmlColor(param2,false);
               break;
            case "Animation":
               _loc3_ = param2.split(",");
               if(_loc3_[0] == "-")
               {
                  this.aEnabled = false;
               }
               else
               {
                  this.frame = parseInt(_loc3_[0]);
                  this.aEnabled = true;
               }
               this.playing = _loc3_.length == 1 || _loc3_[1] == "p";
               break;
            case "Sound":
               _loc3_ = param2.split(",");
               this.sound = _loc3_[0];
               if(_loc3_.length > 1)
               {
                  this.volume = parseInt(_loc3_[1]);
               }
               else
               {
                  this.volume = 0;
               }
               break;
            case "Transition":
               _loc3_ = param2.split(",");
               this.transName = _loc3_[0];
               if(_loc3_.length > 1)
               {
                  this.transTimes = parseInt(_loc3_[1]);
               }
               else
               {
                  this.transTimes = 1;
               }
               break;
            case "Shake":
               _loc3_ = param2.split(",");
               this.shakeAmplitude = parseInt(_loc3_[0]);
               this.shakePeriod = parseFloat(_loc3_[1]);
               if(isNaN(this.shakePeriod))
               {
                  this.shakePeriod = 0.3;
               }
               break;
            case "Visible":
               this.visible = param2 == "true";
               break;
            case "ColorFilter":
               _loc3_ = param2.split(",");
               if(_loc3_.length >= 4)
               {
                  this.filter_cb = parseFloat(_loc3_[0]);
                  this.filter_cc = parseFloat(_loc3_[1]);
                  this.filter_cs = parseFloat(_loc3_[2]);
                  this.filter_ch = parseFloat(_loc3_[3]);
               }
         }
      }
      
      public function encode(param1:String) : String
      {
         var _loc2_:* = null;
         switch(param1)
         {
            case "XY":
            case "Size":
            case "Pivot":
               _loc2_ = "";
               if(this.aEnabled)
               {
                  _loc2_ = _loc2_ + UtilsStr.toFixed(this.a);
               }
               else
               {
                  _loc2_ = _loc2_ + "-";
               }
               _loc2_ = _loc2_ + ",";
               if(this.bEnabled)
               {
                  _loc2_ = _loc2_ + UtilsStr.toFixed(this.b);
               }
               else
               {
                  _loc2_ = _loc2_ + "-";
               }
               return _loc2_;
            case "Alpha":
               return "" + UtilsStr.toFixed(this.alpha);
            case "Rotation":
               return "" + Math.floor(this.rotation);
            case "Scale":
            case "Skew":
               return "" + UtilsStr.toFixed(this.a) + "," + UtilsStr.toFixed(this.b);
            case "Color":
               return UtilsStr.convertToHtmlColor(this.color,false);
            case "Animation":
               _loc2_ = "";
               if(this.aEnabled)
               {
                  _loc2_ = _loc2_ + this.frame;
               }
               else
               {
                  _loc2_ = _loc2_ + "-";
               }
               _loc2_ = _loc2_ + ("," + (!!this.playing?"p":"s"));
               return _loc2_;
            case "Sound":
               if(this.volume != 0)
               {
                  return this.sound + "," + this.volume;
               }
               return this.sound;
            case "Transition":
               if(this.transTimes != 1)
               {
                  return this.transName + "," + this.transTimes;
               }
               return this.transName;
            case "Shake":
               return "" + this.shakeAmplitude + "," + UtilsStr.toFixed(this.shakePeriod);
            case "Visible":
               return "" + this.visible;
            case "ColorFilter":
               return this.filter_cb.toFixed(2) + "," + this.filter_cc.toFixed(2) + "," + this.filter_cs.toFixed(2) + "," + this.filter_ch.toFixed(2);
            default:
               return null;
         }
      }
   }
}
